﻿using BasicLoggerModule.Model;
using BasicLoggerModule.Service;
using log4net.Config;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using log4net;
using Microsoft.Extensions.Logging;
using Volo.Abp.Modularity.PlugIns;

namespace BasicLoggerModule
{
    internal class Program
    {
        static void Main(string[] args)
        {
            new BasicModel().Run();

            #region log4Net日志组件的应用
            {
                //XmlConfigurator.Configure(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4Net.config")));
                Host.CreateDefaultBuilder(args).
                   ConfigureServices((a, b) =>
                   {
                       b.AddApplication<ConsoloModel>();
                       //b.AddApplication<ConsoloModel>(option =>
                       //{
                       //    option.PlugInSources.AddFolder("E:\\项目\\镜像仓库\\twotestapp\\oneapi\\ConsoleAbp\\pluls");
                       //});  //加载插件
                       b.AddLogging(x => { x.ClearProviders(); x.AddLog4Net("log4Net.config"); });
                   }).
                   UseAutofac().
                   RunConsoleAsync().
                   Wait();
            }
            #endregion

            #region log4Net日志组件的应用
            {

                //1、创建WebApplicationBuilder
                HostApplicationBuilder hostApplicationBuilder = Host.CreateApplicationBuilder(args);
                hostApplicationBuilder.Services.AddTransient<ProductService>();
                //hostApplicationBuilder.Configuration.AddJsonFile("appsettings.json");
                //hostApplicationBuilder.Configuration.AddXmlFile("appsettings.xml");
                hostApplicationBuilder.Logging.ClearProviders();
                hostApplicationBuilder.Services.AddLogging(x =>
                {
                    x.AddConfiguration(hostApplicationBuilder.Configuration.GetSection("Logging"));
                    x.AddLog4Net("log4Net.config");
                    x.AddConsole();
                    x.AddSqlserver();
                });
                //创建泛型主机
                IHost host = hostApplicationBuilder.Build();
                //运行console
                host.Run();
                Console.WriteLine("xxx");
            }
            #endregion

        }
    }
}
